<?php
/**个人作品控制器
 * @Author: Administrator
 * @Date:   2014-09-22 22:47:35
 * @Last Modified by:   Administrator
 * @Last Modified time: 2014-11-16 00:11:21
 */
/**
* 
*/
class OpusControl extends CommonControl
{
	private $model;

	public function __auto(){
		$this->model = K('Opus');
	}
	
	public function index()
	{
		$opusdb = $this->model->get_opus_db();
		$category_cid = $opusdb[0]['category_cid'];
		// 醒出分类
		$catedb =K('Category')->get_one(array('cid'=>$category_cid),'cname');
		$this->assign('catedb',$catedb);

		$this->assign('opusdb',$opusdb);
		$this->display();
	}

	public function add()
	{
		if(IS_POST)
		{
			
			// var_dump($_
			// POST);
			// var_dump($_SESSION);
			// die;
			
			if($_POST['category_cid']=='')
			{
				$this->success('请先选择分类',U('index'));
			}
			if(isset($_POST['attr']))
			{
				$attr = implode($_POST['attr'], ',');
			}else{
				$attr="";
			}
			if(!isset($_POST['opus_content']))
			{
				$_POST['opus_content']="";
			}
			
			//标签,TAGS数据--------------------------
			if(isset($_POST['tid'])){
			// 返回的为数据，对数据进行拆分成字符处理
				$tid = implode($_POST['tid'], ',');
			}else{
				$tid="";
			}
			if(isset($_POST['opus_digest'])){
				$digest = $_POST['opus_digest'];
			}else{
				$digest = '';
			}
			
			$opusDB = array(
				'opus_title'=>$_POST['opus_title'],
				'opus_sendtime'=>time(),
				'opus_thumb'=>$_POST['opus_thumb'][1]['path'],
				'opus_digest'=>$digest,
				'attr'=>$attr,
				'opus_author'=>$_POST['opus_author'],
				'category_cid'=>$_POST['category_cid'],
				'user_uid'=>$_SESSION['aid'],
				'opus_lang'=>$_POST['opus_lang'],
				'opus_download'=>$_POST['opus_download'],
				'opus_content'=>$_POST['opus_content'],
				'opus_tags'=>$tid,
				'opus_seelink'=>$_POST['opus_seelink'],

				);
			
			$result  = K('Opus')->add_($opusDB);
			
			if($result)
			{
				$this->success('添加成功',U('index'));

			}else
			{
				$this->error('添加出错','');
			}

			
		}
		$this->display();
	}
	public function del_opus_db()
	{
		$opusid = $_GET['opusid'];
		$result = $this->model->del_opus($opusid);
		
		if($result)
			{
				$this->success('删除成功',U('index'));

			}else
			{
				$this->error('删除出错','');
			}
		$this->diaplay('index.html');
	}
}